package com.bicycle.rentalsystem.dao.impl.user;

import com.bicycle.rentalsystem.dao.user.OnlineDao;
import com.bicycle.rentalsystem.handler.MultiResultHandler;
import com.bicycle.rentalsystem.jdbc.JdbcUtil;
import com.bicycle.rentalsystem.pojo.user.MessageInfo;

import java.util.List;

public class OnlineDaoImpl implements OnlineDao {
    @Override
    public List<MessageInfo> searchMessages() {
        String sql = "SELECT * FROM `online`";
        return JdbcUtil.query(sql,new MultiResultHandler<>(MessageInfo.class));
    }

    @Override
    public int addMessage(String username, String message) {
        String sql = "INSERT INTO `online` (`username`, `message`) VALUES (?, ?)";
        return JdbcUtil.update(sql,username,message);
    }
}
